package com.suntimes.guangjiegou.fragment.shopping;

import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.suntimes.guangjiegou.R;
import com.suntimes.guangjiegou.fragment.BaseFragment;

public class ShoppingFragment extends BaseFragment {

	private GridView mGvCategory;

	protected View loadView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.page_shopping, null, false);
		mGvCategory = (GridView) view.findViewById(R.id.page_shopping_gvCategory);
		mGvCategory.setAdapter(new CategoryAdapter());
		return view;
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
	}

	public class CategoryAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return 9;
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			LinearLayout linearLayout = new LinearLayout(getActivity());
			linearLayout.setOrientation(LinearLayout.VERTICAL);
			linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

			ImageView imgView = new ImageView(getActivity());

			linearLayout.addView(imgView);

			TextView textView = new TextView(getActivity());
			textView.setTextColor(Color.BLACK);
			textView.setGravity(Gravity.CENTER_HORIZONTAL);
			linearLayout.addView(textView);
			linearLayout.setBackgroundResource(R.drawable.gridview_category_item);

			switch (position) {
			case 0:
				textView.setText("数码");
				imgView.setImageResource(R.drawable.goods_category_1);
				break;
			case 1:
				textView.setText("女装");
				imgView.setImageResource(R.drawable.apparel_list_01);
				break;
			case 2:
				textView.setText("男装");
				imgView.setImageResource(R.drawable.apparel_list_02);
				break;
			case 3:
				textView.setText("童装");
				imgView.setImageResource(R.drawable.apparel_list_03);
				break;
			case 4:
				textView.setText("内衣");
				imgView.setImageResource(R.drawable.apparel_list_04);
				break;
			case 5:
				textView.setText("运动");
				imgView.setImageResource(R.drawable.apparel_list_05);
				break;
			case 6:
				textView.setText("箱包");
				imgView.setImageResource(R.drawable.apparel_list_06);
				break;
			case 7:
				textView.setText("配饰");
				imgView.setImageResource(R.drawable.apparel_list_07);
				break;
			case 8:
				textView.setText("鞋类");
				imgView.setImageResource(R.drawable.apparel_list_08);
				break;
			}

			return linearLayout;
		}

	}

}
